home *** CD-ROM | disk | FTP | other *** search
- From: clamage@Eng.Sun.COM (Steve Clamage)
- Message-ID: <4e0u1s$5fv@engnews1.Eng.Sun.COM>
- X-Original-Date: 22 Jan 1996 21:02:52 GMT
- Path: in1.uu.net!bounce-back
- Date: 22 Jan 96 22:23:37 GMT
- Approved: fjh@cs.mu.oz.au
- Newsgroups: comp.std.c++
- Subject: Re: Why no allocator-specific delete?
- Organization: Sun Microsystems Inc.
- References: <4dvid8$460@news.bridge.net>
- Reply-To: clamage@Eng.Sun.COM
- X-Auth: PGPMoose V1.1 PGP comp.std.c++
- iQBFAgUBMQQOguEDnX0m9pzZAQGEOwF+OnlD3HPFcFdNRZMBcj4g1bBodijQqOM3
- CPsTEoHASx1Ou7RP5L8r9WHZU7ISMSyo
- =ezyv
-
- In article 460@news.bridge.net, David Byrden <100101.2547@compuserve.com>
- writes:
- >Why, in the Septenber draft standard, is an allocator-specific verrion of
- >'new' provided;
- >
- >20.1.4.4
- >
- > new(x) T
- >
- > returns an X::types<T>::pointer, where x is of an
- > allocator type X
-
- You are actually referring to the "placement new" syntax not having a
- corresponding "placement delete" syntax.
-
- No good syntax was found for such. The obvious syntax
- delete (x) p;
- leads to too many ambiguities. More importantly, it means that the
- point of deletion would somehow have to know what placement version
- of "new" was used and what the parameters were. Needing that knowledge
- would make "placement delete" unsafe and hard to use. (Consider the
- general case where the "new" and "delete" expressions are in different
- compilation units, and the parameters to "new" affect how "delete"
- should be called.)
-
- You can define a version of "operator delete()" corresponding to a
- placement new. If the constructor for the object exits via an exception,
- the compiler will call the corresponding placement delete automatically
- as a special case.
- T* p = new (x) T;
- The reasons for this special case are
- 1. You do not know what needs to be deleted in general, but the compiler does.
- 2. The compiler has all the information it needs to invoke the special
- operator delete() correctly. It is invoked at the point of the new-expression.
-
- >but there is no matching version of 'delete'? Are we supposed to use both
- >destroy() and deallocate() to get rid of that object?
-
- Yes. In the above example:
- p->~T();
- operator delete(p, x);
-
- ---
- Steve Clamage, stephen.clamage@eng.sun.com
- ---
- [ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu.
- Contact address: std-c++-request@ncar.ucar.edu. The moderation policy
- is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
-